import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { SPetRent } from "../../../../Message/Game/SPetRent";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { PetColor } from "../pet/info/PetColor";
import { PetType } from "../pet/info/PetType";
import { PetUtil } from "../pet/info/PetUtil";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Cache } from "../../cache/Cache";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ObjCreate } from "../common/ObjCreate";
import { PetItem } from "../pet/PetItem";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { Alert } from "../../../../com/mui/controls/Alert";
import { MsgManager } from "../../manager/MsgManager";
import { GButton } from "../../../../com/mui/controls/GButton";
import { TItemPet } from "../../../../Message/Db/Tables/TItemPet";
type int = number;
//class PetHireMarketRenderer
    
    export  class PetHireMarketRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._petRent = arg1 as SPetRent;
            if (this._petRent) 
            {
                this._price = this._petRent.sellPrice;
                this._petItem.setCode(this._petRent.changeCode);
                this._levelColor = GlobalStyle.color6;
                this._levelTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(28023, this._petRent.reinLevel, this._petRent.level), this._levelColor);
                if (this._petRent.code == this._petRent.changeCode) 
                {
                    this._changeStr = "";
                }
                else 
                {
                    this._changeStr = HTMLUtil.addColor(Language.getString(54238), GlobalStyle.color6);
                }
                this._nameTxt.htmlText = this._changeStr + HTMLUtil.addColor(this._petRent.petName, PetColor.getTalentColorByTalent(1, this._petRent.talent).color);
                this._talentTxt.htmlText = HTMLUtil.addColor(this._petRent.talent.toString(), PetColor.getTalentColorByTalent(1, this._petRent.talent).color);
                this._typeTxt.htmlText = HTMLUtil.addColor(PetType.getTypeName(this._petRent.career), PetType.getTypeColor(this._petRent.career));
                this._growthTxt.htmlText = HTMLUtil.addColor(this._petRent.growth.toString(), PetUtil.getUpgradeColor(true, this._petRent.growth));
                this._spiritTxt.htmlText = HTMLUtil.addColor(this._petRent.spirit.toString(), PetUtil.getUpgradeColor(false, this._petRent.spirit));
                this._priceTxt.text = this._price.toString();
                if (this._petRent.sellUnit != EPrictUnit._EPriceUnitCoin) 
                {
                    this._unitImgName = ImagesConst.Yuanbao_small;
                }
                else 
                {
                    this._unitImgName = ImagesConst.Tongqian_small;
                }
                this._unitBitmap.bitmapData = GlobalClass.getBitmapData(this._unitImgName);
                this._cachePet = Cache.instance.pet.getPetInfoByUid(this._petRent.uid);
                if (this._cachePet) 
                {
                    this._tipTxt.visible = true;
                    this._hireBtn.visible = false;
                    this._playerColor = GlobalStyle.color6;
                }
                else 
                {
                    this._tipTxt.visible = false;
                    this._hireBtn.visible = true;
                    this._playerColor = GlobalStyle.color2;
                }
                this._playerTxt.htmlText = HTMLUtil.addColor(this._petRent.ownerName, this._playerColor);
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            var loc2=40;
            var loc3=45;
            ObjCreate.createBg(0, 0, 590, 90, this);
            ObjCreate.createBg(20, 15, 38, 38, this, ImagesConst.PackItemBg);
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            this._petItem.setSize(32, 32);
            this._petItem.move(22, 17);
            this.addChild(this._petItem);
            ObjCreate.createTextField("LV.", 2, 65, 40, 25, this, loc1);
            this._levelTxt = ObjCreate.createTextField("", 24, 65, 40, 25, this, loc1);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt = ObjCreate.createTextField("", 75, 15, 100, 25, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(75, loc2, 75, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54336), 86, loc3, 60, 20, this);
            this._typeTxt = ObjCreate.createTextField("", 75, 65, 75, 20, this, GlobalStyle.textFormat6);
            this._typeTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(155, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54208), 163, loc3, 60, 20, this);
            this._talentTxt = ObjCreate.createTextField("", 155, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._talentTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(205, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54191), 213, loc3, 60, 20, this);
            this._growthTxt = ObjCreate.createTextField("", 205, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._growthTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(255, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54192), 264, loc3, 60, 20, this);
            this._spiritTxt = ObjCreate.createTextField("", 255, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._spiritTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(305, loc2, 100, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54288), 330, loc3, 60, 20, this);
            this._playerTxt = ObjCreate.createTextField("", 305, 65, 100, 20, this, GlobalStyle.textFormat2);
            this._playerTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._detailBtn = ObjCreate.createGButton(Language.getString(54359), 335, 10, 70, 24, this);
            this._detailBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onDetailBtnClickHandler);
            this._detailBtn.drawNow();
            ObjCreate.createTextField(Language.getString(54360), 415, 20, 75, 20, this, GlobalStyle.textFormat2);
            this._priceTxt = ObjCreate.createTextField("", 475, 20, 45, 20, this, GlobalStyle.textFormat2);
            this._priceTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._unitBitmap = ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 517, 20, this);
            ObjCreate.createTextField(Language.getString(54361), 540, 20, 40, 20, this);
            this._tipTxt = ObjCreate.createTextField(Language.getString(54362), 430, 55, 100, 20, this, GlobalStyle.textFormat6);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._hireBtn = ObjCreate.createGButton(Language.getString(54291), 515, 50, 60, 24, this);
            this._hireBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onHireBtnClickHandler);
            this._hireBtn.drawNow();
            return;
        }

        /* internal  */onDetailBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._petRent) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireViewDetail, this._petRent.id));
            }
            return;
        }

        /* internal  */onHireBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var unitName: string;
            var hirePetInfo: SPetInfo;
            var onBtnClickHandler: Function;

            var loc1;
            hirePetInfo = null;
            e = arg1;
            unitName = "";
            if (this._petRent) 
            {
                onBtnClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireBorrow, {"id": _petRent.id, "price": _petRent.sellPrice, "unit": _petRent.sellUnit}));
                        Alert.resetToDefault();
                    }
                    return;
                }
                hirePetInfo = Cache.instance.petHire.hirePetInfo;
                if (hirePetInfo) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54363));
                    return;
                }
                if (this._petRent.sellUnit != EPrictUnit._EPriceUnitCoin) 
                {
                    unitName = Language.getString(54328);
                    if (Cache.instance.role.money.gold < this._price) 
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(54364, unitName));
                        return;
                    }
                }
                else 
                {
                    unitName = Language.getString(54329);
                    if (Cache.instance.role.money.coin < this._price) 
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(54364, unitName));
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this._price));
                        return;
                    }
                }
                Alert.show(Language.getStringByParam(54365, this._price, unitName, this._nameTxt.htmlText), null, Alert.OK | Alert.CANCEL, null, onBtnClickHandler);
            }
            return;
        }

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_typeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_talentTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_growthTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_spiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_detailBtn: GButton;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_hireBtn: GButton;

        /* internal */ /* var */_petRent: SPetRent;

        /* internal */ /* var */_itemPet: TItemPet;

        /* internal */ /* var */_unitImgName: string="";

        /* internal */ /* var */_cachePet: SPetInfo;

        /* internal */ /* var */_changeStr: string="";

        /* internal */ /* var */_levelColor: string;

        /* internal */ /* var */_playerColor: string;

        /* internal */ /* var */_price: int;
    }
